package table;

import mips.Function;
import mips.Reg;
import mips.element.MipsElement;
import symbal.SymbalTable;

import java.util.ArrayList;

public class MipsTable {
    public static ArrayList<MipsElement> _data = new ArrayList<>();
    public static ArrayList<MipsElement> _datastr = new ArrayList<>();
    public static ArrayList<MipsElement> _globalinit = new ArrayList<>();
    public static Function meanfunction = new Function("main");
    public static ArrayList<Function> functions = new ArrayList<>();
    public static Function nowfunction;

    public static int strnum = 0;

    public static SymbalTable mipsTable = new SymbalTable();

    public static void putfunction(String name) {
        nowfunction = new Function(name);
        functions.add(nowfunction);
    }

    public static String toPrint() {
        String str = ".data\n";
        for (MipsElement mipsElement: _data) {
            str += mipsElement.toString() + "\n";
        }
        for (MipsElement mipsElement: _datastr) {
            str += mipsElement.toString() + "\n";
        }
        str += ".text\n";
        for (MipsElement mipsElement: _globalinit) {
            str += mipsElement.toString() + "\n";
        }
        str += meanfunction.toString();
        for (Function function: functions) {
            str += function.toString();
        }
        return str;
    }
}
